#include <iostream>
#include <memory>
#include <string>
#include "EpollServer.hpp"
#include "Protocol.hpp"


std::string echo(std::string str)
{
    return str;
}

using namespace protocol_ns;

Response caculator(const Request &rt)
{
    rt.Print();
    Response rs(0, 0);
    switch (rt._op)
    {
    case '+':
        rs._result = rt._x + rt._y;
        break;
    case '-':
        rs._result = rt._x - rt._y;
        break;
    case '*':
        rs._result = rt._x * rt._y;
        break;
    case '/':
        if (rt._y == 0)
        {
            rs._code = 1;
            return rs;
        }
        rs._result = rt._x / rt._y;
        break;
    case '%':
        if (rt._y == 0)
        {
            rs._code = 2;
            return rs;
        }
        rs._result = rt._x % rt._y;
        break;
    default:
        rs._code=3;
    }
    std::cout<<"result:"<<rs._result<<"[code:"<<rs._code<<"]"<< std::endl;
    return rs;
}

int main()
{
    std::unique_ptr<EpollServer> epollServer(new EpollServer(caculator));

    epollServer->init();
    epollServer->dispatcher();

    return 0;
}